﻿<%@ Page Language="C#" MasterPageFile="~/Shared/Masters/Form.master" AutoEventWireup="true" CodeFile="UserAdd.aspx.cs" 
Inherits="Modules_Sysmgr_UserAdd" Title="用户信息添加" %>

<asp:Content ID="Content2" ContentPlaceHolderID="idFormMain" Runat="Server">
    <script type="text/javascript" src="../../Scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.checktree.0.3.min.js"></script>
    <script type="text/javascript" language="javascript">
        var m_dpmtRootNode = null;
        $(function(){
            var sl = document.createElement("link");
            sl.type = "text/css";
            sl.rel = "stylesheet";
            sl.href = "../../Scripts/css/checktree/checktree.css";
            document.getElementsByTagName("head")[0].appendChild(sl);
        
	        m_dpmtRootNode = $('#treeRoot');
		    showDpmtTree('#treeRoot', '#treeRoot', false, false);
        });
        
        function showDpmtTree(parentObj, rootTag, showCheck, withUpDown) {
	        var tmp = $(parentObj);
	        var needToLoad = false;
        	
	        if (parentObj == rootTag) {
		        if (tmp.find("li").length <= 1) {
			        needToLoad = true;
		        }
	        }
	        else {
		        if (!tmp.parent().attr("loaded")) {
			        needToLoad = true;
		        }
	        }
        	
	        if (needToLoad) {
		        getData(parentObj, function(json){
			        parseAllTree(json[0], parentObj, rootTag, showCheck, withUpDown);
		        });
	        }
        }
        
        function getData(parentDpmt, callback) {
	        var axel = Math.random() + "";
	        var num = axel * 1000000000000000000;
	        var pObj = $(parentDpmt);
	        var pid = "";
	        if (pObj) {
		        var lbl = pObj.parent().find("label");
		        if (lbl) {pid = lbl.attr("cid");}
	        }
        	
	        $.getJSON(
		        "OrgTreeAjax.aspx?ft=all",
		        {dc:num, ppid:pid, getTree:1},
		        function(json) {
			        callback(json);
		        }
	        );
        }
        
        function parseAllTree(data, target, rootTag, sc, wud) {
	        if (data && data.dpmt) {
		        var root = data.dpmt[0];
		        var startIndex = 0;
		        var rootElement = "";
        		
		        if (target != rootTag) {
			        if (data.dpmt.length > 0) {
				        var cid = $(target).parent().find("label").attr("cid");
				        root = {id:cid};
				        startIndex = 0;
			        }
			        else {
				        root = null;
			        }
		        }
		        else {
		            root = {id:0};
		        }
        		
		        rootElement += buildDepartmentTag(root, data.dpmt.slice(startIndex, data.dpmt.length), true);
        		
		        $(target).html(rootElement);
		        buildDpmtTree(target, rootTag, sc, wud);
	        }
        }
        
        function buildDpmtTree(target, rootNode, sc, wud) {
	        var tt = $(target);
	        var rn = m_dpmtRootNode;

	        tt.checkTree({
		        rootObj:rn,
		        index: target == 'treeRoot' ? 1 : 3,
		        showCheck: sc,
		        withUpDown: false,
		        onExpand:function(obj){
			        if (!obj.attr("loaded")) {
				        var tmp = obj.find("ul");
				        tmp.html("loading...");
				        if (tmp && tmp.length > 0){
					        showDpmtTree(tmp[0], rn, sc, wud);
				        }
			        }
			        obj.attr("loaded","true");
		        }
	        });
        	
	        if (target == rootNode) {
		        var r = tt.find('.arrow');
		        if (r.length > 0) {
			        var tmp = $(r[0]);
			        tmp.parent().attr("loaded","true");
			        tmp.trigger('click');
		        }
	        }
        }
        
        function buildDepartmentTag(p, t, isAddChild) {
	        var h = "";
	        for(var i = 0; i < t.length; i++) {
		        var tmp = t[i];
		        if (tmp.parentId == p.id || tmp.parentId == 0) {
			        h += "<li class='parent'><input type='checkbox' class='cb' /><img src='../../Scripts/css/checktree/images/02.jpg' style='width:22px;height:16px;padding:0'/><label type='dpmt' cid='" + tmp.id + "' pid='" + tmp.parentId + "' orgType='" + tmp.type + "' status='" + tmp.status + "' code='" + tmp.code + "'>" + tmp.name + "</label>";
        			
			        var child = buildDepartmentTag(tmp, t.slice(i + 1, t.length), true);
			        var mbt = "";
			        if (child != "" || mbt != null) {
				        h = h + "<ul>" + child + mbt + "</ul>";
			        }
			        h += "</li>";
		        }
	        }
        	
	        return h;
        }
        
        function getSelectedDpmtNode() {
	        var lbs = $('#treeRoot').find('label');
	        if (lbs.length > 0) {
		        for(var i = 0; i < lbs.length; i++) {
			        var lbl = lbs[i];
			        if (lbl.getAttribute("selected") == "true") {
				        return lbl;
			        }
		        }
	        }
	        return null;
        }
    </script>
    <h2>
       <asp:Label ID="lblTitle" runat="server" Text="用户信息添加" ></asp:Label>
    </h2>
<div>
    <table cellpadding='2' cellspacing='1' class='ow_fim_mg' width='100%'>
                <tr>
                    <td class='fi_l'>
                        <asp:Label ID="lbCode" runat="server" Text="账号:"></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:TextBox ID='txtCode' runat='server' Width='120px'
                            ></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvCode" runat="server" ErrorMessage="请输入账号" ValidationGroup="oss"
                    ControlToValidate="txtCode">*</asp:RequiredFieldValidator>
                    </td>
                    <td class='fi_l'>
                        <asp:Label ID="lbName" runat="server" Text="名称:"></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:TextBox ID='txtName' runat='server' Width='120px'
                            ></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvName" runat="server" ErrorMessage="请输入名称" ValidationGroup="oss"
                    ControlToValidate="txtName">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                   <td class='fi_l'>
                        <asp:Label ID="lbPwd" runat="server" Text="密码:" ></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:TextBox ID="txtPwd" runat="server" Width='120px' TextMode="Password" MaxLength='255'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="请输入密码" ValidationGroup="oss"
                    ControlToValidate="txtPwd" >*</asp:RequiredFieldValidator>
                        </td>
                    <td class='fi_l'>
                        <asp:Label ID="lbConfirmPwd" runat="server" Text="确认密码:"></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:TextBox ID="txtConfimPwd" runat="server" Width='120px' TextMode="Password" MaxLength='255'></asp:TextBox>
                          <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="请输入确认密码" ValidationGroup="oss"
                    ControlToValidate="txtConfimPwd" >*</asp:RequiredFieldValidator>
                        </td>
                </tr>   
                <tr>
                    <td class='fi_l'>
                        <asp:Label ID="lbStatus" runat="server" Text="状态:" ></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:DropDownList ID="ddlStatus" runat="server" Width="125px">
                        </asp:DropDownList></td>
                    <td class='fi_l'>
                        <asp:Label ID="lbPost" runat="server" Text="岗位:" ></asp:Label><font color='red'>*</font>
                    </td>
                    <td class='fi_r'>
                        <asp:DropDownList ID="ddlPost" runat="server" Width="125px">
                        </asp:DropDownList></td>   
                </tr>
                <tr>
                    <td class='fi_l'>
                        <asp:Label ID="lbRole" runat="server" Text="所属角色:" ></asp:Label>
                    </td>
                    <td class='fi_r' colspan="3">
                        <asp:CheckBoxList ID="chkRoleList" runat="server" RepeatColumns="3">
                        </asp:CheckBoxList></td>
                </tr>
                <tr>
                    <td class='fi_l'>
                        <asp:Label ID="lbOrg" runat="server" Text="所在部门:"></asp:Label>
                        <input type="hidden" runat="server" ID="hdnOrgID" class="js_unique_orgid" value="" />
                    </td>
                    <td class='fi_r' colspan="3">
                        <ul id="treeRoot" class="tree1 tree" style="margin-left: 5px;OVERFLOW:auto; height:220px;">
			                <li>
				                <label>loading...</label>
			                </li>
		                </ul>
                    </td>
                </tr>
            </table>
</div>

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True"
        ShowSummary="False" ValidationGroup="oss" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="idFormButton" Runat="Server">
  <asp:Button ID="btnSave" runat="server" Text="保存"  ValidationGroup="oss"
        OnClick="btnSave_Click" OnClientClick="doSave();" />
    <asp:Button ID="CloseButton" runat="server" Text="关闭" 
        OnClientClick="return closeForm();" />   
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="idScript" runat="Server">

    <script type="text/javascript">
        function closeForm() {
            window.returnValue="false";
            window.opener=null;
            window.close();
            return false;
        }
       
        function doSave() {
            var obj = getSelectedDpmtNode();
            if(obj) {
                $("input.js_unique_orgid").val(obj.getAttribute("cid"));
            }
        }
    </script>

</asp:Content>



